<template>
  <div class="gift-count-container">
    <div class="header-section">
      <h1 class="title">B站盲盒统计</h1>
      <el-button @click="test" class="test-btn">测试数据</el-button>
    </div>

    <div class="current-user-section">
      <div class="user-card" :class="{ 'profit': nowUser.isZhuan, 'loss': !nowUser.isZhuan }">
        <div class="user-info">
          <div class="user-header">
            <span class="username">{{ nowUser.userName }}</span>
          </div>
          <span v-if="nowUser.isZhuan" class="profit-text">
            这次多薅了 {{ nowUser.price }} 元
          </span>
          <span v-else class="loss-text">
            这次多送了 {{ Math.abs(nowUser.price) }} 元
          </span>
        </div>

        <div class="total-info">
          <span v-if="nowUser.finalPrice >= 0" class="profit-text">
            {{ nowUser.userName }} 一共多薅了 {{ Math.abs(nowUser.finalPrice) }} 元
          </span>
          <span v-else class="loss-text">
            {{ nowUser.userName }} 一共多送了 {{ Math.abs(nowUser.finalPrice) }} 元
          </span>
        </div>
      </div>

      <div class="total-profit-loss">
        <div class="stat-item">
          <span class="stat-label">直播间总盈亏:</span>
          <span v-if="total >= 0" class="stat-value profit-text">
            {{ Math.abs(total) }} 元 (赚)
          </span>
          <span v-else class="stat-value loss-text">
            {{ Math.abs(total) }} 元 (亏)
          </span>
        </div>
      </div>
    </div>

    <div class="stats-section">

      <div class="leaderboard">
        <div class="lucky-section">
          <h3 class="section-title">欧皇榜</h3>
          <div class="leader-item">
            <div class="user-header">
              <span class="username">{{ lucky.userName }}</span>
            </div>
            <span class="profit-text">{{ lucky.finalPrice }} 元</span>
          </div>
        </div>

        <div class="unlucky-section">
          <h3 class="section-title">非酋榜</h3>
          <div class="flash-text-container" v-if="showFlashText">
            <span class="flash-text">让我看看是谁这么倒霉</span>
          </div>
          <transition name="fade">
            <div v-if="showUsername && unlucky.userName !== '无'" class="leader-item">
              <div class="user-header">
                <span class="username">{{ unlucky.userName }}</span>
              </div>
              <span class="loss-text">{{ unlucky.finalPrice }} 元</span>
            </div>
            <div v-else-if="unlucky.userName === '无'" class="leader-item">
              <div class="user-header">
                <span class="username">无</span>
              </div>
              <span class="loss-text">0.0 元</span>
            </div>
          </transition>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
import ChatClientDirectWeb from '@/api/chat/ChatClientDirectWeb'

export default {
  name: 'GiftCountBeautiful',
  props: {
    roomKeyValue: {
      type: [Number, String],
      default: null
    },
  },
  data() {
    return {
      count: 0,
      chatClient: null,
      nowUser: {
        userName: '无',
        price: 0,
        uid: null,
        isZhuan: true,
        finalPrice: 0.0
      },
      lucky: {
        userName: '无',
        price: 0,
        uid: null,
        finalPrice: 0.0
      },
      unlucky: {
        userName: '无',
        price: 0,
        uid: null,
        finalPrice: 0.0
      },
      total: 0.0,
      nowUserMap: null,
      luckyMap: null,
      unluckyMap: null,
      luckyList: [],
      unluckyList: [],
      testJsonList: [
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"bdea3fa8-7a38-400a-b2b3-fec5bff71c41","batch_combo_send":{"action":"投喂","batch_combo_id":"bdea3fa8-7a38-400a-b2b3-fec5bff71c41","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":14000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"逝雪"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"5f2d81ef-6d19-4510-921b-8a7c2a1040c4","combo_num":1,"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":16000,"crit_prob":0,"demarcation":2,"discount_price":16000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":33877,"giftName":"神奇金杯","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":16000,"rcost":9159165,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841370731074048","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841370731074048","timestamp":1711167612,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"0db940e2-a6d5-4e95-9525-137b2d48574c","batch_combo_send":{"action":"投喂","batch_combo_id":"0db940e2-a6d5-4e95-9525-137b2d48574c","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":9000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":32126,"gift_name":"棉花糖","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":9000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"89bf8e73-5468-41be-b9b9-623766dad834","combo_num":1,"gift_id":32126,"gift_name":"棉花糖","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":9000,"crit_prob":0,"demarcation":2,"discount_price":9000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":32126,"giftName":"棉花糖","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":9000,"rcost":9159095,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841347532364800","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841347532364800","timestamp":1711167606,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"bdea3fa8-7a38-400a-b2b3-fec5bff71c41","batch_combo_send":{"action":"投喂","batch_combo_id":"bdea3fa8-7a38-400a-b2b3-fec5bff71c41","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"5f2d81ef-6d19-4510-921b-8a7c2a1040c4","combo_num":1,"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":16000,"crit_prob":0,"demarcation":2,"discount_price":16000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":33877,"giftName":"神奇金杯","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":16000,"rcost":9159165,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841370731074048","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841370731074048","timestamp":1711167612,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"0db940e2-a6d5-4e95-9525-137b2d48574c","batch_combo_send":{"action":"投喂","batch_combo_id":"0db940e2-a6d5-4e95-9525-137b2d48574c","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":9000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":32126,"gift_name":"棉花糖","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":9000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"89bf8e73-5468-41be-b9b9-623766dad834","combo_num":1,"gift_id":32126,"gift_name":"棉花糖","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":9000,"crit_prob":0,"demarcation":2,"discount_price":9000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":32126,"giftName":"棉花糖","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":9000,"rcost":9159095,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841347532364800","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841347532364800","timestamp":1711167606,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"fead68a2-ece8-44ba-9036-efd702d51536","batch_combo_send":{"action":"投喂","batch_combo_id":"fead68a2-ece8-44ba-9036-efd702d51536","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"d1f6f3d3-8dde-40f2-999d-599ce68d9a80","combo_num":1,"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":16000,"crit_prob":0,"demarcation":2,"discount_price":16000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":33877,"giftName":"神奇金杯","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":16000,"rcost":9159165,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841364615865856","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841364615865856","timestamp":1711167610,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"c43b3758-f53d-4eba-9fd8-db8422da34c5","batch_combo_send":{"action":"投喂","batch_combo_id":"c43b3758-f53d-4eba-9fd8-db8422da34c5","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":9000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":32126,"gift_name":"棉花糖","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":9000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"c19aadc2-32a6-4a50-a009-eff07ca37fc7","combo_num":1,"gift_id":32126,"gift_name":"棉花糖","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":9000,"crit_prob":0,"demarcation":2,"discount_price":9000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":32126,"giftName":"棉花糖","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":9000,"rcost":9159095,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841340620195328","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841340620195328","timestamp":1711167605,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"bc68b732-870f-4b1b-bf3c-f4becc36cb0c","batch_combo_send":{"action":"投喂","batch_combo_id":"bc68b732-870f-4b1b-bf3c-f4becc36cb0c","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":16000,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":15000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"7a159b20-325a-494f-a0dd-3826b2a946f8","combo_num":1,"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":16000,"crit_prob":0,"demarcation":2,"discount_price":16000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":33877,"giftName":"神奇金杯","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":16000,"rcost":9159165,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841334207117312","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841334207117312","timestamp":1711167603,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"bc68b732-870f-4b1b-bf3c-f4becc36cb0c","batch_combo_send":{"action":"投喂","batch_combo_id":"bc68b732-870f-4b1b-bf3c-f4becc36cb0c","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":5200,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":5000},"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":5200,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":5000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"7a159b20-325a-494f-a0dd-3826b2a946f8","combo_num":1,"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"Miyyooo"},"combo_stay_time":5,"combo_total_coin":16000,"crit_prob":0,"demarcation":2,"discount_price":16000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":33877,"giftName":"神奇金杯","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":16000,"rcost":9159165,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841334207117312","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"Miyyooo","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"Miyyooo"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841334207117312","timestamp":1711167603,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"Miyyooo","wealth_level":54}',
        '{"action":"投喂","bag_gift":null,"batch_combo_id":"bc68b732-870f-4b1b-bf3c-f4becc36cb0c","batch_combo_send":{"action":"投喂","batch_combo_id":"bc68b732-870f-4b1b-bf3c-f4becc36cb0c","batch_combo_num":1,"blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":5200,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":5000},"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"test1"},"beatId":"","biz_source":"live","blind_gift":{"blind_gift_config_id":51,"from":0,"gift_action":"爆出","gift_tip_price":5200,"original_gift_id":32251,"original_gift_name":"心动盲盒","original_gift_price":5000},"broadcast_id":0,"coin_type":"gold","combo_resources_id":1,"combo_send":{"action":"投喂","combo_id":"7a159b20-325a-494f-a0dd-3826b2a946f8","combo_num":1,"gift_id":33877,"gift_name":"神奇金杯","gift_num":1,"send_master":null,"uid":3493089012353967,"uname":"test1"},"combo_stay_time":5,"combo_total_coin":16000,"crit_prob":0,"demarcation":2,"discount_price":16000,"dmscore":1512,"draw":0,"effect":0,"effect_block":0,"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","face_effect_id":0,"face_effect_type":0,"float_sc_resource_id":0,"giftId":33877,"giftName":"神奇金杯","giftType":0,"gift_tag":[],"gold":0,"group_medal":null,"guard_level":2,"is_first":true,"is_join_receiver":true,"is_naming":false,"is_special_batch":0,"magnification":1,"medal_info":{"anchor_roomid":0,"anchor_uname":"","guard_level":0,"icon_id":0,"is_lighted":0,"medal_color":0,"medal_color_border":0,"medal_color_end":0,"medal_color_start":0,"medal_level":0,"medal_name":"","special":"","target_id":0},"name_color":"#E17AFF","num":1,"original_gift_name":"","price":16000,"rcost":9159165,"receive_user_info":{"uid":3546577291446858,"uname":"漫听-阚卿"},"receiver_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","is_mystery":false,"name":"漫听-阚卿","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/f9516d8625bfe7829c500f8b2eaa7c1805bd6a94.jpg","name":"漫听-阚卿"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3546577291446858,"wealth":null},"remain":0,"rnd":"4488841334207117312","send_master":null,"sender_uinfo":{"base":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","is_mystery":false,"name":"test1","name_color":0,"name_color_str":"","official_info":{"desc":"","role":0,"title":"","type":-1},"origin_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"test1"},"risk_ctrl_info":{"face":"https://i0.hdslb.com/bfs/face/7309629379c24813c382a90e767a8e2d4adb24d3.jpg","name":"test1"}},"guard":null,"guard_leader":null,"medal":null,"title":null,"uhead_frame":null,"uid":3493089012353967,"wealth":null},"silver":0,"super":0,"super_batch_gift_num":1,"super_gift_num":1,"svga_block":0,"switch":true,"tag_image":"","tid":"4488841334207117312","timestamp":1711167603,"top_list":null,"total_coin":15000,"uid":3493089012353967,"uname":"test1","wealth_level":54}'
      ],
      showFlashText: false,
      showUsername: true
    }
  },
  beforeDestroy() {
    if (this.chatClient) {
      this.chatClient.stop()
    }
  },
  methods: {
    test() {
      const randomIndex = Math.floor(Math.random() * this.testJsonList.length)
      let tesjson = this.testJsonList[randomIndex]
      this.onAddGift2(tesjson)
    },
    init() {
      this.nowUserMap = new Map()
      this.unluckyMap = new Map()
      this.luckyMap = new Map()
    },
    initClient() {
      console.log(this.roomKeyValue)
      this.chatClient = new ChatClientDirectWeb(this.roomKeyValue)
      this.chatClient.onAddText = this.onAddText
      this.chatClient.onAddGift = this.onAddGift
      this.chatClient.start()
    },
    onAddGift2(data) {
      let dataJson = JSON.parse(data)
      let num = dataJson.super_gift_num
      if (dataJson.blind_gift && dataJson.batch_combo_send) {
        let sendUser = dataJson.batch_combo_send
        let blindGift = sendUser.blind_gift
        let userName = sendUser.uname
        let uid = sendUser.uid
        let price = ((blindGift.gift_tip_price - blindGift.original_gift_price) * num / 1000).toFixed(1)
        this.total = (parseFloat(this.total) + parseFloat(price)).toFixed(1)
        let isZhuan
        let finalPrice = price

        let tempUser
        if (this.nowUserMap && this.nowUserMap.has(userName)) {
          tempUser = this.nowUserMap.get(userName)
          if (tempUser.userName == userName) {
            finalPrice = (parseFloat(tempUser.finalPrice) + parseFloat(price)).toFixed(1)
          }
        }
        this.nowUser.userName = userName
        this.nowUser.price = price
        this.nowUser.uid = uid
        this.nowUser.finalPrice = finalPrice

        let tempUser2 = {
          userName,
          price,
          uid,
          finalPrice
        }
        this.nowUserMap.set(userName, tempUser2)

        if (blindGift.gift_tip_price >= blindGift.original_gift_price) {
          isZhuan = true
          this.nowUser.isZhuan = isZhuan
          console.log('用户', userName, '赚了', price)
          let tempUserLuck = {
            userName,
            price,
            uid,
            finalPrice
          }
          if (finalPrice > 0) {
            this.luckyMap.set(userName, tempUserLuck)
          } else {
            this.unluckyMap.set(userName, tempUserLuck)
          }
          this.luckyList = [...this.luckyMap.values()]
          this.luckyList.sort((a, b) => b.finalPrice - a.finalPrice)
          this.lucky = this.luckyList[0]
          this.unluckyList = [...this.unluckyMap.values()]
          this.unluckyList.sort((a, b) => a.finalPrice - b.finalPrice)
          if (this.lucky) {
            if (this.lucky.userName == this.unlucky.userName && finalPrice > 0) {
              this.unlucky.userName = '无'
              this.unlucky.finalPrice = 0.0
            } else if (this.lucky.userName == this.unlucky.userName && finalPrice < 0) {
              finalPrice = (parseFloat(this.lucky.finalPrice) + parseFloat(this.unlucky.finalPrice)).toFixed(1)
              this.lucky.userName = '无'
              this.lucky.finalPrice = 0.0
              this.lucky.finalPrice = finalPrice
            }
            if (finalPrice < 0) {
              this.unlucky = this.unluckyList[0]
            }
          } else {
            this.lucky = {
              userName: '无',
              finalPrice: 0.0
            }
            this.unlucky = this.unluckyList[0]
          }
        } else {
          isZhuan = false
          this.nowUser.isZhuan = isZhuan
          console.log('用户', userName, '亏了', price)
          let tempUserUnLuck = {
            userName,
            price,
            uid,
            finalPrice
          }
          if (finalPrice < 0) {
            this.unluckyMap.set(userName, tempUserUnLuck)
          } else {
            this.luckyMap.set(userName, tempUserUnLuck)
          }
          this.unluckyList = [...this.unluckyMap.values()]
          this.unluckyList.sort((a, b) => a.finalPrice - b.finalPrice)
          this.unlucky = this.unluckyList[0]
          if (this.unlucky) {
            if (this.lucky.userName == this.unlucky.userName && finalPrice < 0) {
              this.lucky.userName = '无'
              this.lucky.finalPrice = 0.0
            } else if (this.lucky.userName == this.unlucky.userName && finalPrice > 0) {
              finalPrice = (parseFloat(this.lucky.finalPrice) + parseFloat(this.unlucky.finalPrice)).toFixed(1)
              this.unlucky.userName = '无'
              this.unlucky.finalPrice = 0.0
              this.unlucky.finalPrice = finalPrice
            }
          } else {
            this.unlucky = {
              userName: '无',
              finalPrice: 0.0
            }
            this.luckyList = [...this.luckyMap.values()]
            this.luckyList.sort((a, b) => b.finalPrice - a.finalPrice)
            this.lucky = this.luckyList[0]
          }
        }
      }
    },
    onAddGift(dataJson) {
      console.log(dataJson)
      console.log(dataJson.super_gift_num)
      let num = dataJson.super_gift_num
      if (dataJson.blind_gift && dataJson.batch_combo_send) {
        let face = dataJson.face
        let sendUser = dataJson.batch_combo_send
        let blindGift = sendUser.blind_gift
        let userName = sendUser.uname
        let uid = sendUser.uid
        let price = ((blindGift.gift_tip_price - blindGift.original_gift_price) * num / 1000).toFixed(1)
        this.total = (parseFloat(this.total) + parseFloat(price)).toFixed(1)
        let isZhuan
        let finalPrice = price

        let tempUser
        if (this.nowUserMap && this.nowUserMap.has(userName)) {
          tempUser = this.nowUserMap.get(userName)
          if (tempUser.userName == userName) {
            finalPrice = (parseFloat(tempUser.finalPrice) + parseFloat(price)).toFixed(1)
          }
        }
        this.nowUser.userName = userName
        this.nowUser.price = price
        this.nowUser.uid = uid
        this.nowUser.finalPrice = finalPrice
        this.nowUser.face = face

        let tempUser2 = {
          userName,
          price,
          uid,
          finalPrice,
          face
        }
        this.nowUserMap.set(userName, tempUser2)

        if (blindGift.gift_tip_price >= blindGift.original_gift_price) {
          isZhuan = true
          this.nowUser.isZhuan = isZhuan
          console.log('用户', userName, '赚了', price)
          let tempUserLuck = {
            userName,
            price,
            uid,
            finalPrice
          }
          if (finalPrice > 0) {
            this.luckyMap.set(userName, tempUserLuck)
          } else {
            this.unluckyMap.set(userName, tempUserLuck)
          }
          this.luckyList = [...this.luckyMap.values()]
          this.luckyList.sort((a, b) => b.finalPrice - a.finalPrice)
          this.lucky = this.luckyList[0]
          this.unluckyList = [...this.unluckyMap.values()]
          this.unluckyList.sort((a, b) => a.finalPrice - b.finalPrice)
          if (this.lucky) {
            if (this.lucky.userName == this.unlucky.userName && finalPrice > 0) {
              this.unlucky.userName = '无'
              this.unlucky.finalPrice = 0.0
            } else if (this.lucky.userName == this.unlucky.userName && finalPrice < 0) {
              finalPrice = (parseFloat(this.lucky.finalPrice) + parseFloat(this.unlucky.finalPrice)).toFixed(1)
              this.lucky.userName = '无'
              this.lucky.finalPrice = 0.0
              this.lucky.finalPrice = finalPrice
            }
            if (finalPrice < 0) {
              this.unlucky = this.unluckyList[0]
            }
          } else {
            this.lucky = {
              userName: '无',
              finalPrice: 0.0
            }
            this.unlucky = this.unluckyList[0]
          }
        } else {
          isZhuan = false
          this.nowUser.isZhuan = isZhuan
          console.log('用户', userName, '亏了', price)
          let tempUserUnLuck = {
            userName,
            price,
            uid,
            finalPrice
          }
          if (finalPrice < 0) {
            this.unluckyMap.set(userName, tempUserUnLuck)
          } else {
            this.luckyMap.set(userName, tempUserUnLuck)
          }
          this.unluckyList = [...this.unluckyMap.values()]
          this.unluckyList.sort((a, b) => a.finalPrice - b.finalPrice)
          this.unlucky = this.unluckyList[0]
          if (this.unlucky) {
            if (this.lucky.userName == this.unlucky.userName && finalPrice < 0) {
              this.lucky.userName = '无'
              this.lucky.finalPrice = 0.0
            } else if (this.lucky.userName == this.unlucky.userName && finalPrice > 0) {
              finalPrice = (parseFloat(this.lucky.finalPrice) + parseFloat(this.unlucky.finalPrice)).toFixed(1)
              this.unlucky.userName = '无'
              this.unlucky.finalPrice = 0.0
              this.unlucky.finalPrice = finalPrice
            }
          } else {
            this.unlucky = {
              userName: '无',
              finalPrice: 0.0
            }
            this.luckyList = [...this.luckyMap.values()]
            this.luckyList.sort((a, b) => b.finalPrice - a.finalPrice)
            this.lucky = this.luckyList[0]
          }
        }
      }
    },
    async onAddText(data) {
      console.log(data.authorName, '说', data.content)
    },
    showName() {
      this.showUsername = true;
    },
     showFlashAnimation() {
      this.showFlashText = true;
      this.showUsername = false;
      
      // 动画持续时间1秒，然后恢复正常显示
      setTimeout(() => {
        this.showFlashText = false;
        this.showUsername = true;
      }, 1000);
    },
  },
  mounted() {
    this.init()
    // this.initClient()
  },
  watch: {
    'unlucky.userName': {
      handler(newVal, oldVal) {
        console.log(newVal, oldVal)
        // 只有当从"无"变为有数据时才显示动画
        if (newVal && newVal !== '无'  && newVal !== oldVal) {
          this.showFlashAnimation();
        }
      },
    }
  }
}
</script>

<style scoped>
.gift-count-container {
  max-width: 400px;
  margin: 0 auto;
  padding: 10px;
  font-family: 'Arial', sans-serif;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  color: #333;
}

.header-section {
  text-align: center;
  margin-bottom: 15px;
}

.title {
  font-size: 1.8rem;
  font-weight: bold;
  margin: 0;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
  background: linear-gradient(to right, #ffd700, #ffa500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.current-user-section {
  margin-bottom: 15px;
}

.user-card {
  background: #f5f5f5;
  border-radius: 6px;
  padding: 10px;
  border: 1px solid #ddd;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.user-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.user-card.profit {
  border-left: 5px solid #4caf50;
}

.user-card.loss {
  border-left: 5px solid #f44336;
}

.user-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.user-header {
  display: flex;
  align-items: center;
  gap: 10px;
}



.username {
  font-size: 1.2rem;
  font-weight: bold;
}

.leader-item .username {
  font-size: 1rem;
}

.profit-text {
  color: #4caf50;
  font-weight: bold;
}

.loss-text {
  color: #f44336;
  font-weight: bold;
}

.total-info {
  font-size: 0.9rem;
}

.stats-section {
  background: #f5f5f5;
  border-radius: 6px;
  padding: 10px;
  border: 1px solid #ddd;
}

.total-stats {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ddd;
}

.total-profit-loss {
  background: #f5f5f5;
  border-radius: 6px;
  padding: 10px;
  border: 1px solid #ddd;
  margin: 15px 0 15px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
}

.stat-label {
  font-size: 1rem;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: bold;
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lucky-section,
.unlucky-section {
  background: #f9f9f9;
  border-radius: 5px;
  padding: 4px;
}

.section-title {
  margin-top: 0;
  margin-bottom: 15px;
  text-align: center;
  color: #ffd700;
}

.lucky-section .section-title {
  color: #4caf50;
}

.unlucky-section .section-title {
  color: #f44336;
}

.leader-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
}

@media (max-width: 768px) {
  .gift-count-container {
    padding: 8px;
    max-width: 350px;
  }

  .title {
    font-size: 1.3rem;
  }

  .leaderboard {
    grid-template-columns: 1fr;
  }

  .user-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }

  .user-header {
    align-self: flex-start;
  }

  .username {
    font-size: 1rem;
  }

  .username {
    font-size: 1rem;
  }

  .stat-label {
    font-size: 0.8rem;
  }

  .stat-value {
    font-size: 0.9rem;
  }


}

.flash-text-enter-active {
  animation: flash 1s ease-in-out;
}

.flash-text-leave-active {
  transition: opacity 0.3s;
}

.flash-text-leave-to {
  opacity: 0;
}

@keyframes flash {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    filter: blur(10px);
  }

  20% {
    opacity: 1;
    transform: scale(1.1) translateY(0);
    filter: blur(0);
  }

  80% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.9);
  }
}

.flash-text-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  min-width: 200px; /* 添加最小宽度确保容器足够宽 */
  text-align: center; /* 确保文字居中 */
}

.flash-text {
  font-size: 18px;
  font-weight: bold;
  color: #ff4757;
  text-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
  background: linear-gradient(45deg, #ff6b6b, #ff4757, #ff3838);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 10px 20px;
  border-radius: 8px;
  white-space: nowrap; /* 添加这行防止换行 */
}

.leader-item {
  position: relative;
}
.unlucky-section {
  position: relative;
  min-height: 100px; /* 确保有足够空间容纳动画和内容 */
}

.flash-text-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  animation: flash 1s ease-in-out;
}

@keyframes flash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
    filter: blur(10px);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
    filter: blur(0);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
</style>